﻿using CPPEI;
using CPPEI.WebApi;
using SLG.Domain.Services;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace SLG.WebApi.Kingdom
{
    /// <summary>
    /// 创建王国
    /// </summary>
    [AuthPostAction("Kingdom", "Create", "1.0")]
    public class CreateAction : BaseAction<CreateParams, CreateResult>
    {
        protected override ActionResult<CreateResult> OnExecute(ActionContext context, SysParameters sysParams, CreateParams opParams)
        {
            int userId = Convert.ToInt32(context.UserId);

            CreateService service = new CreateService();
            SingleResult<Domain.Datas.KingdomAndKing> serResult = service.CreateKingdom(userId, opParams.Race, opParams.King, opParams.Name);
            if(serResult.IsSuccess)
            {
                CreateResult actResult = new CreateResult();
                actResult.KingdomId = serResult.Data.Kingdom.Id;
                actResult.KingdomName = serResult.Data.Kingdom.Name;
                actResult.KingId = serResult.Data.King.Id;
                actResult.KingName = serResult.Data.King.Name;
                actResult.Race = serResult.Data.Kingdom.BDRaceId;
                return new ActionResult<CreateResult>(actResult);
            }
            else
            {
                return new ActionResult<CreateResult>(serResult);
            }
        }
    }

    public class CreateParams
    {
        /// <summary>
        /// 选择的种族
        /// </summary>
        public int Race { get; set; }

        /// <summary>
        /// 选择的国王
        /// </summary>
        public int King { get; set; }

        /// <summary>
        /// 国王名称
        /// </summary>
        public string Name { get; set; }
    }

    public class CreateResult
    {
        /// <summary>
        /// 王国id
        /// </summary>
        public Guid KingdomId { get; set; }

        public string KingdomName { get; set; }

        /// <summary>
        /// 国王id
        /// </summary>

        public Guid KingId { get; set; }

        public string KingName { get; set; }

        public int Race { get; set; }
    }
}
